{include file="header.html"}
<script type="text/javascript">
    $(function () {
        $('#ad_form').validate({
            errorPlacement: function (error, element) {
                $(element).next('.field_notice').hide();
                $(element).after(error);
            },
            success: function (label) {
                label.addClass('right').text('OK!');
            },
            onkeyup: false,
            rules: {
        {if !$ad.ad_pic}
        ad_pic: {
            required: true,
                accept: 'gif|png|jpe?g'
        },
        {/if}
            ad_name: {
                required: true,
            }
        },
        messages: {
            {if !$ad.ad_pic}
            ad_pic: {
                required: '{$lang.ad_logo_empty}',
                    accept: '{$lang.limit_img}'
            },
            {/if}
                ad_name: {
                    required: '{$lang.ad_name_empty}',
                }
            }
        });
    });
</script>
<div id="rightTop">
    <p>自定义标签</p>
    <ul class="subnav">
        <li><a class="btn1" href="index.php?app=custom_label">管理</a></li>
        <li><span>编辑</span></li>
    </ul>
</div>

<div class="info">
    <form method="post" enctype="multipart/form-data" id="custom_label_form">
        <table class="infoTable">
            <tr>
                <th class="paddingT15">
                    标签名称:</th>
                <td class="paddingT15 wordSpacing5" >
                    <input class="infoTableFile2" id="label_name" name="label_name" value="{$res.label_name}"/>
                </td>
            </tr>
            <tr>
                <th class="paddingT15">
                    选择商品:</th>
                <td class="paddingT15 wordSpacing5">
                    <button class="formbtn cart-add" type="button">选择</button>
                    <div class="choose_goods" style="padding-top:20px ">
            <tr class="tatr1" id="after">
                <td width="30%"><span ectype="order_by" fieldname="goods_name">商品名称</span></td>
                <td class="10%"><span ectype="order_by" fieldname="default_image">缩略图</span></td>
                <td width="30%"><span ectype="order_by" fieldname="views">操作</span></td>
            </tr>
            <!--{foreach from=$res.goods item=bg}-->
            <tr class="tatr1">
                <td width="30%">
                    <label style="padding: 5px; border:1px solid #e3e3e3 ;" name="goods" value="{$bg.goods_id}">{$bg.goods_name}</label>
                </td>
                <td class="table-center"><img  height="80" src="{$bg.default_image}" /></td>
                <td class="table-center">
                    <input type="checkbox" checked style="display: none" value="{$bg.goods_id}" name="goods"><img style="margin-right: 10px;width:15px;height: 15px;" src="templates/style/images/close.gif" onclick="dropGoods(this)" fieldname="mall_recommended" fieldid="{$bg.goods_id}" fieldvalue="1" title="{$lang.editable}"/>
                </td>
            </tr>
            <!--{/foreach}-->
</div>
<input id="goods_id" name="goods_id" style="display: none" value="{$res.goods_id}">
</td>
</tr>
<tr>
    <th class="paddingT15">
        {$lang.sort_order}:</th>
    <td class="paddingT15 wordSpacing5" >
        <input class="infoTableFile2" id="sort_order" type="number" name="sort_order" value="{$res.sort_order}"/>
    </td>
</tr>
<tr>
    <th></th>
    <td class="ptb20">
        <input class="formbtn" type="submit" name="Submit" value="{$lang.submit}" />
        <input class="formbtn" type="reset" name="Submit2" value="{$lang.reset}" />
    </td>
</tr>
</table>
</form>



<div class = "bg-model" style="position:absolute;top:0%;left:0%;display:none;background:rgba(0,0,0,0.3);width:100%;height:100%;position:fixed;z-index:9999">
    <iframe src="index.php?app=goods&act=iframe" id="goods_page" width="90%" height="90%"></iframe>
</div>

</div>
{include file="footer.html"}
<script>
    var goods_id = '';
    $(function () {
    })
    $(".cart-add").click(function () {
        $("iframe").contents().find(".checkitem:checked");
        $("iframe").contents().find(".checkitem:checked").each(function () {
            $(this).removeAttr('checked');
        })
        $("iframe").contents().items = '';
        $(".bg-model").fadeTo(300,1)
        //隐藏窗体的滚动条
        $("body").css({ "overflow": "hidden" });
    });

    //模态框OK按钮点击事件
    $(".bg-model-ok").click(function () {
        $(".bg-model").hide();
        //显示窗体的滚动条
        $("body").css({ "overflow": "visible" });
    }).hover(function () {
        $(this).css({ "backgroundColor": "#8CC8C8" });
    }, function () {
        $(this).css({ "backgroundColor": "#8CD4E6" });
    });
    $("#enter").click(function () {
        var items = '';
        var name = '';
        $('.checkitem:checked').each(function(){
            items += this.value + ',';
            name += $(this).attr('attr-name') + ','
        });
        items = items.substr(0, (items.length - 1));
        name = name.substr(0, (name.length - 1));

        var items_arr = items.split(',');
        var name_arr = name.split(',');
        for(var i in items_arr){
            $(".choose_goods").append('' +
                '<label style="padding: 5px; border:1px solid #e3e3e3" name="goods" value="'+items_arr[i]+'">'+name_arr[i]+'</label><input type="checkbox" checked style="display: none" value="'+items_arr[i]+'" name="goods"><img style="margin-right: 10px;width:15px;height: 15px;" src="templates/style/images/close.gif" onclick="dropGoods(this' +
                ')" fieldname="mall_recommended" fieldid="{$goods.goods_id}" fieldvalue="1" title="{$lang.editable}"/>'
            );
        }
        $('#goods_id').val($('input[name="goods"][type=checkbox]:checked').map(function(){return this.value}).get().join(','));
        $(".bg-model").hide();
        //显示窗体的滚动条
        $("body").css({ "overflow": "visible" });
    })
    function dropGoods(obj) {
        $(obj).parent().parent().remove();
        $(obj).remove()
        $('#goods_id').val($('input[name="goods"][type=checkbox]:checked').map(function(){return this.value}).get().join(','));
    }

</script>
